package appcus

import (
	"counter-help/admin/server/global"
	appReq "counter-help/admin/server/model/app/response"
	"counter-help/admin/server/model/common/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// AppDataApi 后台数据中心
type AppDataApi struct {
}

// RequireIncreaseApi 新增需求的数量
func (a *AppDataApi) RequireIncreaseApi(c *gin.Context) {
	var resp appReq.AppRequireIncreaseResponse
	global.GVA_LOG.Info("数据中心处理新增需求数量")
	resp, err := appDataService.RequireIncreaseService()
	if err != nil {
		global.GVA_LOG.Error("获取新增需求数量失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
		return
	}

	response.OkWithDetailed(resp, "获取新增需求数量成功", c)
}

// OrderIncreaseApi 新增订单数量
func (a *AppDataApi) OrderIncreaseApi(c *gin.Context) {
	var resp appReq.AppOrderIncreaseResponse
	global.GVA_LOG.Info("数据中心处理新增订单数量")
	resp, err := appDataService.OrderIncreaseService()
	if err != nil {
		global.GVA_LOG.Error("获取新增订单数量失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
		return
	}

	response.OkWithDetailed(resp, "获取新增订单数量成功", c)
}

// UserIncreaseApi 新增订单数量
func (a *AppDataApi) UserIncreaseApi(c *gin.Context) {
	var resp appReq.AppUserIncreaseResponse
	global.GVA_LOG.Info("数据中心处理新增用户数量")
	resp, err := appDataService.UserIncreaseService()
	if err != nil {
		global.GVA_LOG.Error("获取新增用户数量失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
		return
	}

	response.OkWithDetailed(resp, "获取新增用户数量成功", c)
}

// OrderWeeklyCountApi 统计最近7周的订单数量
func (a *AppDataApi) OrderWeeklyCountApi(c *gin.Context) {
	global.GVA_LOG.Info("数据中心处理最近7周的订单数量")

	// 调用服务层获取数据
	resp, err := appDataService.GetOrderCountLast7Weeks()
	if err != nil {
		global.GVA_LOG.Error("获取最近7周订单数量失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
		return
	}

	response.OkWithDetailed(resp, "获取最近7周订单数量成功", c)
}
